define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chase/auto_category/index' + location.search,
                    add_url: 'chase/auto_category/add',
                    edit_url: 'chase/auto_category/edit',
                    del_url: 'chase/auto_category/del',
                    multi_url: 'chase/auto_category/multi',
                    table: 'auto_category',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'onlineswitch', title: __('Onlineswitch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (e, data) {
                                return ` <a href="javascript:;" class="btn btn-xs btn-primary btn-service" data-id="`+data.id+`" >服务</a> ` +
                                    `<a href="javascript:;" class="btn btn-xs btn-primary btn-dragsort" title="拖动进行排序"><i class="fa fa-arrows"></i></a> ` +
                                    ` <a href="javascript:;" class="btn btn-xs btn-success btn-editone" title="编辑" ><i class="fa fa-pencil"></i></a> ` +
                                    ` <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="删除" ><i class="fa fa-trash"></i></a> `;

                            }}
                    ]
                ]
            });

            table.on('click', '.btn-service', function () {
                var id = $(this).data('id')
                Fast.api.open('/shijiu.php/chase/auto_service/category?category_id='+id, '自主买单服务列表')
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});